<template lang="pug">
transition(name="fade")
  .preview(v-show="show", @click="close($event)")
    .preview-container
      img(ref="img", :src="url | filterSrc")
</template>

<script>
import { mapState, mapActions } from 'vuex'
export default {
  name: 'previewModal',
  data () {
    return {
      
    }
  },
  computed: {
    ...mapState({
      show: state => state.ui.preview.show,
      url: state => state.ui.preview.url, // 要显示的图片组
    }),
  },
  methods: {
    ...mapActions([
      'changePreviewModal',
    ]),
  	close (e) {
  	  if (e.target !== this.$refs.img && e.target !== this.$refs.last && e.target !== this.$refs.next) {
  	    this.changePreviewModal({show: false})
  	  }
  	}
  }
}
</script>

<style scoped lang="scss">
.fade-enter-active,
.fade-leave-active {
  opacity: 0;
  transform: scale(1.2)
}
.preview {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,.5);
  display: table;
  transition: all .2s ease;
  z-index: 9999;
  .preview-container {
    width: 720px;
    height: 720px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    & img {
      max-width: 100%;
      max-height: 100%;
    }
  }
}
</style>
